<include file="Store:header"/>
<link rel="stylesheet" href="/assets/public/mobiscroll/css/mobiscroll.custom-3.0.0-beta2.min.css">
<div class="wraper space">
	<a href="/base/address/address/order_id/{BEESCRM:$order_id}/store_id/{BEESCRM:$storeId}/type/1003/picked/{BEESCRM:$picked}" class="list-info status">
		<span class="iconfont icon-location"></span>
		<if condition="$data['order']['username']">
			{BEESCRM:$data.order.username}&nbsp;&nbsp;&nbsp;&nbsp;
		</if>
		<if condition="$data['order']['mobile']">
			{BEESCRM:$data.order.mobile}&nbsp;&nbsp;&nbsp;&nbsp;
		</if>
		<if condition="$data['order']['address'] and $picked eq 0">
			{BEESCRM:$data.order.address}
		</if>
		<if condition="$data['order']['address_id'] lt 1 and $picked eq 0">
			请添加地址
		<elseif condition="$data['order']['address_id'] lt 1 and $picked eq 1"/>
			请添加联系方式
		</if>
		<div class="product-img"><span class="iconfont icon-you pull-right"></span></div>
	</a>
    <div class="order-list">
        <a href="{BEESCRM::U('base/storeOld/index',array('store_id'=>$storeId))}" class="shop">
        	<span class="iconfont icon-dianpu"></span>
        	{BEESCRM:$data.store_name} <span class="iconfont icon-you"></span>
        </a>
		<volist name="data['order']['StoreOrderGoods']" id="vo">
	        <div class="list-info order">
	            <div class="product-img"><img src="{BEESCRM:$vo.goods_thumb}"></div>
	            <div class="product-info">
	                <p>{BEESCRM:$vo.goods_name}</p>
	                <p class="prize"><span>￥{BEESCRM:$vo.goods_price}</span> <span>X{BEESCRM:$vo.goods_num}</span></p>
	                <if condition="$vo['spec'] neq ''">
	                <p class="prize">规格：{BEESCRM:$vo.spec}</p>
	                </if>
	            </div>
	        </div>
        </volist>
    </div>
    <if condition="$storeId eq 82">
    	<!--杭师大-->
		<div class="form-list" style="margin-bottom: 10px;"><input id="date" placeholder="请选择取货时间"></div>
	</if>

    <div class="order-info">

        <textarea placeholder="给卖家留言" class="leave-message" id="remark">{BEESCRM:$data.order.remark}</textarea>

        <div class="list">
            <p class="text-right">
            	共 <span class="strong-red">{BEESCRM:$data.order.StoreOrderGoods|count}</span> 件商品 &nbsp;&nbsp;&nbsp;
				优惠：<span class="strong-red">￥{BEESCRM:$data.order.discount}</span>
            </p>
            <p class="text-right">
 				合计：<span class="strong-red">￥{BEESCRM:$data.order.order_amount}</span></p>
        </div>
    </div>

    <div class="btn-box bottom clearfix">
        <p class="pull-left"><span class="account">合计：<span>￥{BEESCRM:$data.order.order_amount}</span></span></p>
        <p class="pull-right"><a href="javascript:void(0)" class="btn pay" id="submit">确认付款</a></p>
    </div>

    <input type="hidden" id="order_id" value="{BEESCRM:$order_id}" />
</div>
<include file="Store:commonJs"/>
<script src="/assets/public/mobiscroll/mobiscroll.custom-3.0.0-beta2.min.js"></script>
<script>
	var currYear = (new Date()).getFullYear();
	var opt={};
	opt.date = {preset : 'date'};
	opt.datetime = {preset : 'datetime'};
	opt.time = {preset : 'time'};
	opt.default = {
		theme: 'ios', //皮肤样式
		display: 'bottom', //显示方式
		mode: 'scroller', //日期选择模式
		lang:'zh',
		startYear:currYear - 10, //开始年份
		endYear:currYear + 10 //结束年份
	};

	var optDateTime = $.extend(opt['datetime'], opt['default']);
	var optTime = $.extend(opt['time'], opt['default']);
	$("#date").mobiscroll(optDateTime).datetime(optDateTime);
</script>
<script type="text/javascript">
	$(function(){
		var order_id=$('#order_id').val();

		//确认付款
		$(document).on('click','#submit',function(){

			var remark=$('#remark').val();
			var json={};
			/* //收货地址验证
			var address_id="{BEESCRM:$data.order.address_id}";
			if(!address_id || address_id=='0'){
				$.alert('error','请选择收货地址');return;
			} */
			json.url="{BEESCRM::U('base/storeOld/payNumDec',array('store_id'=>$storeId))}";
			json.method="post";
			json.data={
					'order_id':order_id,
					'remark':remark,
			};
			<if condition="$storeId eq 82">
				var timeline = $('#date').val();
				if(!timeline){
					$.alert('error','请选择取货日期');return;
				}
				json.data.pretime = timeline;
			</if>
			<if condition="$paySuccess">
				$.getAjax(json,false,paySuccess,show_error);
			<else/>
				$.getAjax(json,false,pay,show_error);
			</if>
		});

		//数据处理错误
		function show_error(data){
			$.alert('error',data.message);
			if(data.url){
				setTimeout('location.href="'+data.url+'"',2000);
			}
		}
		<if condition="!$paySuccess">
			//微支付
			function pay(){
				if (typeof WeixinJSBridge == "undefined"){
					if( document.addEventListener ){
						document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
					}else if (document.attachEvent){
						document.attachEvent('WeixinJSBridgeReady', jsApiCall);
						document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
					}
				}else{
					WeixinJSBridge.invoke(
						'getBrandWCPayRequest',
						{BEESCRM:$wxpay},
						function(res){
							WeixinJSBridge.log(res.err_msg);
							if(res.err_msg == "get_brand_wcpay_request:ok"){
								paySuccess();
							}else if(res.err_msg == "get_brand_wcpay_request:cancel"){
								$.alert('error','你肯定不是真的想抛弃我们～');
								return false;
							}else{
								$.alert('error','哎呀，网络不给力，小微又调皮了，咋们刷新再来一次');
								setTimeout("location.reload()",2000);
								return false;
							}
						}
					);
				}
			}
		</if>

		function paySuccess(){
			var json={};
			json.url="{BEESCRM::U('base/storeOld/paysuccess',array('origin'=>$origin,'store_id'=>$storeId))}/order_id/"+order_id;
			$.getAjax(json,false,redirect);
		}

		function redirect(data){
			location.href=data.url;
		}
	});
</script>
<include file="Store:footer" />
